package com.g5.edu.mapper;

import com.g5.edu.model.DfUsersInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.g5.edu.model.Permission;
import com.g5.edu.model.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;


import java.util.List;

/**
* <p>
    * 用户表 Mapper 接口
    * </p>
*
* @author admin
* @since 2021-10-29
*/
@Repository
public interface DfUsersInfoMapper extends BaseMapper<DfUsersInfo> {

    @Select("SELECT p.id , p.name\n" +
            "FROM df_users_info u\n" +
            "LEFT JOIN user_role ur ON u.id = ur.user_id\n" +
            "LEFT JOIN role r ON r.id = ur.role_id\n" +
            "LEFT JOIN role_permission rp ON r.id = rp.role_id\n" +
            "LEFT JOIN permission p ON p.id = rp.permission_id\n" +
            "WHERE u.id = #{id}")
    List<Permission> findUserPermissionsById(Integer id);

    @Select("select * from df_users_info where username=#{username}")
    DfUsersInfo findUserByUsername(String username);

    @Select("SELECT r.id , r.name FROM df_users_info u\n" +
            "LEFT JOIN user_role ur ON u.id = ur.user_id\n" +
            "LEFT JOIN role r ON r.id = ur.role_id\n" +
            "WHERE u.id = #{id}")
    List<Role> findUserRolesById(Integer id);
}
